home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: why arrays may seem like pointers
- Date: 28 Feb 1996 16:05:48 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4h2qksINN6fl@anvil.ugrad.cs.ubc.ca>
- References: <4gsdno$1bg@umbc9.umbc.edu> <313318b8.53776146@nntp.ix.netcom.com> <DnHyrp.CF8@eskimo.com> <3134A1C7.3FB7@oc.com>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <3134A1C7.3FB7@oc.com>, Larry Weiss <lfw@oc.com> wrote:
- >Steve Summit wrote:
- > >
- > > Having learned this, I'm now careful to say things like, "When
- > > you make reference to an array in an expression, the compiler
- > > automatically generates a pointer to its first element, just as
- > > if you'd written &array[0]." I try to use words like "generate,"
- > > and *not* to use words like "convert."
- > >
- >
- >Also, it is common jargon to say the array reference "decays" into
- >a pointer. The word "decay" confused me when I first learned the
- >language, as it conveys that something actually happened to the array.
- >
- >If you are quite naive, and still pondering strange "algebraic"
- >expressions like
- > x = x + 1
- >then it's even more important to get clear explanations of array
- >semantics. It's actually "too bad" that one must understand pointers
- >in order to understand arrays, in general, but then, that's C.
-
- That is not true. To just learn basic array manipulation, you don't have to be
- aware that pointers are involved. The [] postfix operator doesn't readily
- betray that it is equivalent to (*(E1 + (E2)). Not until you need to pass an
- array into a function, anyway! :)
-
- It's possible to conceive of a language that is like C in every regard except
- the equivalence of E1[E2] and *(E1 + (E2)), and related equivalences. In this
- imaginary language, the only way to get the address of element 0 of an array
- is to use &array[0]. An expression consisting of only the name of the
- serves as an lvalue for the purpose of array assignment, passing by
- value or returning an array from a function. It is still possible to use []
- with pointers: it is an overload operator, the same way you can use + for
- pointer arithmetic, integer arithmetic or floating-point arithmetic.
- Is there anything in this language that is excessively clumsy to express
- compared to using a C idiom?
- --
-
-